import java.util.*;

public class Solution_1 {
    static class City {
        int cost;
        int happiness;
        City(int cost, int happiness) {
            this.cost = cost;
            this.happiness = happiness;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        List<City> cities = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            cities.add(new City(x, y));
        }

        cities.sort(Comparator.comparingInt(a -> a.cost));

        long maxHappiness = 0;
        long currentHappiness = 0;
        int left = 0;

        for (int right = 0; right < n; right++) {
            currentHappiness += cities.get(right).happiness;

            while (cities.get(right).cost - cities.get(left).cost >= k) {
                currentHappiness -= cities.get(left).happiness;
                left++;
            }

            maxHappiness = Math.max(maxHappiness, currentHappiness);
        }

        System.out.println(maxHappiness);
    }
}
